#pragma once
#include <functional>
#include <ctime>
#include <iostream>
#include <string>
#include <vector>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <unistd.h>
using namespace std;

typedef function<void()> task_t;
// using task_t = function<void()>;

void Download()
{
    cout << "正在执行下载任务"
         << "    处理者 :" << getpid() << endl;
}

void WatchingMovies()
{
    cout << "正在执行看电影任务"
         << "    处理者 :" << getpid() << endl;
}

void ListenMusic()
{
    cout << "正在执行听音乐任务"
         << "    处理者 :" << getpid() << endl;
}

class task
{
public:
    task()
    {
        tasks.push_back(Download);
        tasks.push_back(WatchingMovies);
        tasks.push_back(ListenMusic);
        srand(time(nullptr));
    }
    int RandomSending()
    {
        return rand() % tasks.size();
    }
    void RunTask(int code)
    {
        tasks[code]();
    }
    string HashName(int code)
    {
        switch (code)
        {
        case g_download_code:
            return "download task";
        case g_watchingmovies_code:
            return "watchingmovies task";
        case g_listenmusic_code:
            return "listenmusic task";
          default:
            return "Unknow";
        }
    }

public:
    static const int g_download_code = 0;
    static const int g_watchingmovies_code = 1;
    static const int g_listenmusic_code = 2;
    vector<task_t> tasks;
};

task init;